#include "vec2.h"

vec2::vec2()
:x(0),y(0)
{
}

vec2::vec2(float x_,float y_)
:x(x_),y(y_)
{
}

vec2::vec2(float value)
:x(value),y(value)
{
}

vec2::vec2(const vec2 &copy)
:x(copy.x),y(copy.y)
{
}




inline vec2& vec2::operator =(const vec2 &other)
{
	x = other.x;
	y = other.y;

	return *this;
}

inline bool vec2::operator == (const vec2 &other) const
{
	return (x == other.x) && (y == other.y);
}

inline bool vec2::operator != (const vec2 &other) const
{
	return (x != other.x) || (y != other.y);
}

inline vec2 vec2::operator +(const vec2 &other) const
{
	return vec2(x + other.x, y + other.y);
}

inline vec2 vec2::operator +(float value) const
{
	return vec2(x + value, y + value);
}

inline vec2 vec2::operator *(const vec2 &other) const
{
	return vec2(x * other.x, y * other.y);
}

inline vec2 vec2::operator *(float value) const
{
	return vec2(x * value, y * value);
}


inline vec2& vec2::operator +=(const vec2 &other)
{
	x+=other.x;
	y+=other.y;

	return *this;
}

inline vec2& vec2::operator +=(float value)
{
	x+=value;
	y+=value;

	return *this;
}

inline vec2& vec2::operator *=(const vec2 &other)
{
	x*=other.x;
	y*=other.y;

	return *this;
}

inline vec2& vec2::operator *=(float value)
{
	x*=value;
	y*=value;

	return *this;
}


inline vec2 vec2::operator -(const vec2 &other) const
{
	return vec2(x - other.x, y - other.y);
}

inline vec2 vec2::operator -(float value) const
{
	return vec2(x - value, y - value);
}

inline vec2 vec2::operator /(const vec2 &other) const
{
	return vec2(x / other.x, y / other.y);
}

inline vec2 vec2::operator /(float value) const
{
	return vec2(x / value, y / value);
}


inline vec2& vec2::operator -=(const vec2 &other)
{
	x -= other.x;
	y -= other.y;

	return *this;
}

inline vec2& vec2::operator -=(float value)
{
	x -= value;
	y -= value;

	return *this;
}

inline vec2& vec2::operator /=(const vec2 &other)
{
	x /= other.x;
	y /= other.y;

	return *this;
}

inline vec2& vec2::operator /=(float value)
{
	x /= value;
	y /= value;

	return *this;
}

inline vec2 vec2::operator +() const
{
	return vec2(x,y);
}

inline vec2 vec2::operator -() const
{
	return vec2(-x,-y);
}



inline vec2::operator float*()
{
	return &x;
}

inline vec2::operator const float*() const
{
	return &x;
}

inline float vec2::operator [] (int index)
{
	return *(&x + index);
}

inline float vec2::len() const
{
	return sqrt(x*x + y*y);
}

inline void vec2::normalize()
{
	float l = len();
	x /= l;
	y /= l;
}

inline float vec2::getangle() const
{
	return atan2(x,y);
}

void vec2::turn(float angle)
{
	float l = len();
	float a = getangle() + angle;

	SinCos(a,x,y);

	x *= l;
	y *= l;
}

inline vec2 vec2::lerp(const vec2 &other, float scalar) const
{
	return vec2(x + (other.x - x) * scalar
		,y + (other.y - y) * scalar);
}

inline void vec2::lerpme(const vec2 &other, float scalar)
{
	x += (other.x - x) * scalar;
	y += (other.y - y) * scalar;
}
